package com.example.club.clubmanage.utils;

import android.content.Context;
import android.widget.Toast;

import com.example.club.clubmanage.MyApplication;


/**
 * @author
 * @since 2018-8-8
 */
public class ToastUtil {

    //定义静态Toast对象，优化多次弹出提示的显示时间。
    private static Toast mToast;

    //参数使用Application的context，防止内存泄露
    public static void showToastShort(Context context, String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(msg);
        }
        mToast.show();
    }

    public static void showToastLong(Context context, String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
        } else {
            mToast.setText(msg);
        }
        mToast.show();
    }

    public static void showToastShort(String msg) {
        showToastShort(MyApplication.application, msg);
    }

    public static void showToastLong(String msg) {
        showToastLong(MyApplication.application, msg);
    }
}
